/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicios5_5;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 *
 * @author Mañana
 */
public class Ejercicios5_5 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        try {
            //Declaramos el Archivo
            //Buscamos el Fichero que queremos mostrar
            File newTextFile = new File("./QUIJOTE.txt");
            BufferedReader fr = new BufferedReader(new FileReader (newTextFile));
            int i = 0;
            int cont = 0;
            String pal = " ";
            boolean leopal = false;
            while ((i = fr.read()) != -1) {
                if (Character.isLetter((char) i)) {
                    if (leopal) {
                        pal += (char) i;
                    } else {
                        leopal = true;
                        pal += (char) i;
                    }

                } else {
                    if (leopal) {
                        leopal = false;
                        cont++;
                        pal = "";
                    } else {
                    }
                }
            }
            fr.close();

            System.out.println("Palabras: " + cont);

        } catch (IOException ex) {
            System.out.println("Excepcion de IO.");
        }
    }
}
